home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000109_icon-group-sender _Sat Apr 27 10:27:41 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Sat, 27 Apr 1996 07:41:07 MST
  2. Message-Id: <3181E88D.7DB5@tees.ac.uk>
  3. Date: Sat, 27 Apr 1996 10:27:41 +0100
  4. From: Hamish Lawson <H.Lawson@tees.ac.uk>
  5. Organization: University of Teesside, School of Computing and Maths
  6. X-Mailer: Mozilla 2.01Gold (Win95; I)
  7. Mime-Version: 1.0
  8. To: icon-group@cs.arizona.edu
  9. Subject: Re: Splitting and joining strings
  10. References: <199604172119.QAA18647@post.its.mcw.edu>
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: O
  15.  
  16. Thanks to everyone who responded to my post about splitting and joining 
  17. strings. I had hesitated about posting the question, suspecting that it would 
  18. be thought too trivial, but I was interested by how many different solutions 
  19. were offered to this 'trivial' problem :-). Bob Alexander provided the solution 
  20. which came closest to what I was after, which (with some modifications I've 
  21. made to the join procedure) I present below for anyone who's interested.
  22.  
  23. procedure join(stringList,separator)
  24.   local result
  25.   result := get(stringList)
  26.   every result ||:= separator || !stringList
  27.   return result
  28. end
  29.  
  30. procedure split(string,separator)
  31.   local result
  32.   string ? {
  33.     until pos(0) do {
  34.       result := tab(find(separator) | 0)
  35.       suspend result
  36.       move(*separator)
  37.     }
  38.   }
  39. end
  40.  
  41. | Hamish Lawson, School of Computing and Mathematics, 
  42. | University of Teesside, Middlesbrough, Cleveland, UK, TS1 3BA 
  43. | Tel: +44 1642 212695  Fax: +44 1642 342604
  44. | E-mail: H.Lawson@tees.ac.uk
  45.